/*-
 * Copyright (c) 2006, 2007 FTS Team
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 4. Neither the name of the FTS Team nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *      LemCache.hpp
 *
 * $FTS$
 */
#ifndef _LEM_CACHE_HPP__
#define _LEM_CACHE_HPP__ 1

/**
  @file LemCache.hpp
  @brief Cache for lemmatized words
*/
#include <HashFunctions.hpp>
#include <Hash.hpp>
#include <LemmatizerInterface.hpp>

#define C_MAX_FIRST_FORMS 6

namespace FTSS // FullTextSearchSystem
{

/**
  @struct CachedWord LemCache.hpp <LemCache.hpp>
  @brief Cached word
*/
struct CachedWord
{
	/** Word hash */
	TokenHash_t   word_hash;
	/** Word form */
	CHAR_8        word_form;
};

/**
  @class LemCache LemCache.hpp <LemCache.hpp>
  @brief Cache for lemmatized words
*/
class LemCache
{
public:
	/**
	  @brief Constructor
	  @param oILemmatizer - lemmatizer instance
	  @param iDictSize - initial dictionary size
	*/
	LemCache(LemmatizerInterface & oILemmatizer, Size_t iDictSize = (1 << 0));

	/**
	  @brief Get cached word from word cache
	  @param sWord - word
	  @param iWordLength - word length
	  @return Array of cached words
	*/
	CachedWord * GetWord(CCHAR_P sWord, const UINT_32 & iWordLength);

	/**
	  @brief A destructor
	*/
	~LemCache() throw();

private:

	/**
	  @typedef Pair<TokenHash_t, CachedWord *> LemPair
	  @brief Data storage type definition
	*/
	typedef Pair<TokenHash_t, CachedWord *> LemPair;

	/**
	  @typedef Hash<TokenHash_t, CachedWord *, HashHasher, HashComparator> LemHash
	  @brief Data storage key => value pair type definition
	*/
	typedef Hash<TokenHash_t, CachedWord *, HashHasher, HashComparator> LemHash;

	/** Lemmatizer instance      */
	LemmatizerInterface  & oLemmatizer;
	/** Hash of lemmatized words */
	LemHash                oLemHash;
	/** Cached words             */
	CachedWord           * aCachedWord;
};

} // namespace FTSS
#endif // _LEM_CACHE_HPP__
// End.
